<template>
    <div class="myorder">
        <div class="header">
            <van-nav-bar title="我的订单" left-arrow @click-left="onClickLeft" />
        </div>
        <div v-if="isLoaing" class="order_null">
            <div class="loading">
                <van-loading type="spinner" />
            </div>
        </div>
        <div v-if="orderlist.list.length == 0 && !isLoaing" class="order_null">
            <i></i>
            <p>您暂时没有订单纪录</p>
            <button>随便逛逛</button>
        </div>
        <div class="order_list">
            <div class="order_box" v-for="item in orderlist.list" :key="item.order_id">
                <p class="order_id">订单编号:{{ item.order_id }}</p>
                <div class="order_detail">
                    <div class="order_img">
                        <!-- <img :src="`https://images.weserv.nl/?url=${item.order_img}`" alt="" /> -->
                        <img :src="item.order_img" alt="" />
                    </div>
                    <div class="order_title">
                        <p class="order_name">{{ item.order_name }}</p>
                        <p class="order_style">
                            颜色:<span class="color">{{ item.order_color }}</span
                            >尺码:<span>{{ item.order_size }}</span>
                        </p>
                    </div>
                    <div class="order_price">
                        <p class="price">￥{{ item.order_price }}</p>
                        <p class="num">×{{ item.order_num }}</p>
                    </div>
                </div>
                <p class="price_all">
                    共计{{ item.order_num }}件商品 合计:<span>￥{{ item.order_price * item.order_num }}</span
                    >(含运费￥0.00)
                </p>
                <div class="order_footer">
                    <button class="detele" @click="remove(item.order_id)">删除</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { getOrder, removeOrder } from "../../api/index";
import { reactive, ref } from "vue";

let orderlist = reactive({
    list: [],
});
let isLoaing = ref(true);

const remove = (order_id: any) => {
    let data = {
        order_id,
    };
    removeOrder(data).then((res: any) => {
        if (res.code == 200) {
            getOrder({ order_status: 2 }).then((res: any) => {
                orderlist.list = res.content;
            });
        }
    });
};

const onClickLeft = () => history.back();

getOrder({ order_status: 2 }).then((res: any) => {
    // console.log(res);
    orderlist.list = res.content;
    isLoaing.value = false;
});
</script>

<style lang="scss" scoped>
.myorder {
    width: 100%;
    background: #f0f0f0;
    // height: 1000px;
    .header {
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
    }

    .order_null {
        height: 620px;
        // margin-top: 50px;
        width: 60%;
        padding-top: 100px;
        margin: 0 auto;
        .loading {
            text-align: center;
            margin-top: 100px;
        }

        i {
            margin: 0 auto;
            display: block;
            width: 150px;
            height: 150px;
            background-image: url(@/assets/order.png);
            background-repeat: no-repeat;
            background-size: 100%;
        }
        p {
            margin-top: 10px;
            text-align: center;
            font-size: 16px;
            color: #313131;
        }
        button {
            margin-top: 30px;
            padding: 10px 0;
            border: 1px solid #353535;
            background: #353535;
            font-size: 14px;
            color: #fff;
            border-radius: 5px;
            width: 100%;
        }
    }

    .order_list {
        padding-top: 47px;
        width: 100%;
    }
    .order_box {
        box-shadow: 0 5px 10px -5px #999;
        margin-bottom: 20px;
        background: #fff;
        padding: 15px;
        .order_id {
            font-size: 12px;
            color: #999;
            padding-bottom: 10px;
        }
        .order_detail {
            display: flex;
        }
        .order_img {
            width: 20%;
            // width: 69px;
            height: 73px;
            img {
                width: 100%;
                height: 100%;
            }
        }
        .order_title {
            width: 60%;
            padding-left: 10px;
            .order_name {
                font-size: 14px;
                color: #353535;
                height: 38px;
            }
            .order_style {
                // margin-top: 5px;
                font-size: 13px;
                color: #999;

                span {
                    padding-right: 10px;
                }
            }
        }
        .order_price {
            width: 20%;
            text-align: right;
            .price {
                font-size: 16px;
                color: #c7273a;
            }
            .num {
                margin-top: 20px;
                font-size: 13px;
                color: #999;
            }
        }
        .price_all {
            padding-top: 10px;
            font-size: 12px;
            color: #999;
            text-align: right;
            span {
                font-size: 13px;
                color: #c7273a;
            }
        }
        .order_footer {
            padding-top: 10px;
            text-align: right;

            button {
                border: 1px solid #c7273a;
                background: #c7273a;
                color: #fff;
                font-size: 14px;
                border-radius: 20px;
                padding: 2px 15px;
            }
        }
    }
}
:deep(.van-nav-bar) {
    background: #353535;
}
:deep(.van-nav-bar__title) {
    color: #fff;
    font-weight: normal;
}
:deep(.van-nav-bar .van-icon) {
    color: #fff;
}
</style>
